//
//  ZHVisitorController.swift
//  ZHWeibo
//
//  Created by user on 15/12/5.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

class ZHVisitorController: UITableViewController {
    
    //在LoadView确定到底应该加载哪一种控制器----拦截系统方法
    var isLogin = true
    //声明访客视图的变量
    var vistorView:ZHVistorView?
    override func loadView() {
        isLogin ? super.loadView() : setUpVisitorView()
    }
    private func setUpVisitorView() {
        /**
          * 这里不传frame没有问题吗？
        */
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: nil, title: "注册", target: self, action: "clickregistor")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: nil, title: "登录", target: self, action: "clickLogin")
        vistorView = ZHVistorView()
        vistorView?.loginClosure = {
            /**
            *  为什么这里要使用self
            */
            self.clickLogin()
        }
        vistorView?.registerClosure = {
            self.clickregistor()
        }
        view = vistorView
    }
    //点击注册/登录方法
    @objc private func clickregistor() {
        print("点击了注册")
    }
    @objc private func clickLogin() {
        print("点击了登录")
        //跳转OAuth认证
        let controller: ZHOAuthController = ZHOAuthController()
        presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}